﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Member.Model;
using Member.BLL;
using Member.IBLL;

namespace Merber.Controllers
{
    public class AdminController : Controller
    {
        private IAdminBLL adminbll=new AdminBLL();
        //
        // GET: /Admin/
        public ActionResult Login()
        {
            return View();
        }
        [HttpPost]
        //管理员登陆
        public ActionResult Login(FormCollection fc)
        {
            string id=fc["name"].ToString();
            string pwd=Md5Encrypt.GetMd5ByString( fc["password"].ToString());
            
            Admin ad = adminbll.login(p => p.admin_id ==id);
            if (ad!=null)
            {
                if (pwd == ad.admin_pwd)
                {
                    Session["user"] = ad;
                    //登陆成功
                    return RedirectToAction("Index", "Page");
                }
                else
                {
                    ViewBag.ms = "密码错误";
                    //密码错误
                    return View("Login");
                }
            }
            else
            {
                ViewBag.ms = "用户名错误";
                return View("Login");
                //登陆失败
            }
        }

        /// <summary>
        /// 管理员退出
        /// </summary>
        /// <returns></returns>
        public ActionResult outlogin()
        {
            if(Session["user"]!=null)
                Session.Remove("user");
            return View("Login");
        }
	}
}